(function(){
    'use strict';
	angular.module('webApp').controller('PartnerCtrl',PartnerCtrl);
	PartnerCtrl.$inject=['$scope','dataService','$location','$state','helper']
	function PartnerCtrl($scope,dataService,$location,$state,helper){
		$scope.listAction=function(){
			$scope.page_Size=10;
			$scope.partnerGet(1);
		}
		$scope.partnerGet=function(page_No){
			var query={page_no:page_No,page_size:$scope.page_Size};
			if($scope.partner_id){
				query.query={partner_id:partner_id}
			}
			dataService.partnerGet(query).then(function(result){
				$scope.partners=result.shop;
				$scope.partnersTotal = result.total_count;
			});
		}
		$scope.addAction=function(){
			var partner_id= $location.search().partner_id;
			if(partner_id){
				dataService.partnerOne(partner_id).then(function(result){
					$scope.partner=result;	
				});	
			}else{
				$scope.partner={};
				$scope.partner.usr="";
				$scope.partner.user_name='21231223';
				$scope.partner.pwd="";
				$scope.partner.password="a123";
				$scope.partner.password_confirm="a123";

				$scope.partner.name="33";
				$scope.partner.logo="http://localhost:8080/static/uploads/160623952/2016-09-09/10863a65ab1d572074f1c772c7707b94.png"
				// $scope.partner.grade_id=2222222222;
				// $scope.partner.product_line=111111;
				// $scope.partner.trade_type="DEALER";
				// $scope.partner.auth_payway="支付宝";
				// $scope.partner.tel=13241234214123;
				$scope.partner.phone=3123442213;
				$scope.partner.email="21312@164.com";
				// $scope.partner.address="北京海淀望月桥";
			}
		}
		$scope.partnerAdd=function(){
			if($scope.partner.partner_id){
				dataService.partnerUpdate($scope.partner).then(function(result){
					if(result.Msg){
	 					helper.myAlert("error:"+result.Msg)
	 				}else{
	 					helper.myAlert("success",null,null,function(){
	 						$state.go("partner.list");
	 					})
	 				}
				});
			}else{
				dataService.partnerAdd($scope.partner).then(function(result){
					if(result.Msg){
	 					helper.myAlert("error:"+result.Msg)
	 				}else{
	 					helper.myAlert("success",null,null,function(){
	 						$state.go("partner.list");
	 					})
	 				}
				})
			}
		}
		$scope.partnerDelete=function(partner_id){
			dataService.partnerDelete(partner_id).then(function(r){
				if(r.Msg){
	 					helper.myAlert("error:"+r.Msg)
	 				}else{
	 					helper.myAlert("success",null,null,function(){
	 						$scope.listAction();
	 					})
	 				}
			});
		}
		$scope.infoAction=function(){
			console.log('111');
			var partner_id=	$location.search().partner_id;
			dataService.partnerOne(partner_id).then(function(result){
				$scope.partner=result;
			});
		}
	}
})();